import express from 'express';
import controller from './controller';
import multer from 'multer';
//定义 DiskStorage 对象
const storage = multer.diskStorage({
    //对存储路径进行配置
    destination:function(_req,_file,callback){
        callback(null,'upload/images/')
    },
    //对文件名进行配置
    filename:function(_req,file,callback){
        //生成唯一文件名：时间戳 + 原文件扩展名
        callback(null,Date.now() + "." + file.originalname.split('.').pop())
    }
})
//定义 Multer 对象
const upload = multer({ 
    storage:storage
})
//导出路由配置
export default express
    .Router()
    .post('/image/upload',upload.single('file'),controller.upload)